//
//  FallCollectionViewCell.m
//  collectViewDemo
//
//  Created by wulanzhou on 2016/11/4.
//  Copyright © 2016年 wulanzhou. All rights reserved.
//

#import "FallCollectionViewCell.h"
#import "UIColor+CZExtend.h"

@implementation FallCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame{
    
    if (self=[super initWithFrame:frame]) {
        
        [self addSubview:self.titleLabel];
        self.backgroundColor = [UIColor randomColor];
        
        //选中时的背景色
        UIView *selectedBackgroundView = [[UIView alloc] init];
        self.selectedBackgroundView.backgroundColor = [UIColor lightGrayColor];
        self.selectedBackgroundView = selectedBackgroundView;
        
    }
    return self;
}

- (UILabel *)titleLabel{

    if (!_titleLabel) {
        
        _titleLabel=[[UILabel alloc] initWithFrame:self.bounds];
        _titleLabel.backgroundColor=[UIColor clearColor];
        _titleLabel.textColor = [UIColor redColor];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.font = [UIFont systemFontOfSize:14.0f];
        _titleLabel.numberOfLines = 0;
        _titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
    }
    
    return _titleLabel;
}

- (void)layoutSubviews{

    [super layoutSubviews];
    
    CGSize size = [self.titleLabel.text textSize:self.titleLabel.font withWidth:self.width];
    CGRect r=self.titleLabel.frame;
    r.size = size;
    r.origin.x = (self.width - r.size.width )/2;
    r.origin.y = (self.height - r.size.height)/2;
    
    self.titleLabel.frame = r;
}

@end
